<template>
	<view>
		<view>
			<image class="topbg" src="/static/images/topbg.png" mode=""></image>
			<view class="title">您好，欢迎使用三麻四友管理平台</view>
		</view>
		<!-- 登录 -->
		<view class="lgoin">
			<view>登录</view>
			<input type="text" placeholder="账号" v-model="account" />
			<input type="password" placeholder="密码" v-model="password" />
			<button class="btn" @click="login()">登录</button>
		</view>
	</view>
</template>

<script>
	import { BASE_URL } from '@/config.js'
	export default {
		data() {
			return {
				account: '', //15757115639
				password: ''
			};
		},
		methods: {
			login() {
				this.https('/login/login', {
					mobile: this.account,
					password: this.password
				}).then(res => {
					const { msg } = res
					if (res.code == 1) {
						const { avatar } = res.data
						if (!avatar.startsWith('http')) {
							res.data.avatar = `${BASE_URL}${avatar}`
						}
						// 缓存店铺ID
						// uni.setStorageSync('storeListId', res.data.store_ids.split(','));
						// 缓存店铺信息
						const { store_info } = res.data
						if (!!store_info && store_info.length) {
							this.$store.commit('setStoreList', { value: store_info, init: true })
						}
						this.$store.commit("setUserInfo", res.data)
						uni.setStorageSync('should_update', '888')
						// uni.setStorageSync('storeList', store_info);
						// 缓存tokne
						// uni.setStorageSync('token', res.data.token);
						// 缓存用户信息
						// uni.setStorageSync('userinfo', res.data);
						this.$toast({ title: msg });
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/index/index'
							});
						}, 1500);
					} else {
						this.$toast({ title: msg });
					}
				}).catch(() => {
					this.$toast({ title: '登录失败' })
				});
			}
		}
	};
</script>

<style lang="scss">
	.topbg {
		width: 750rpx;
		height: 561rpx;
		position: relative;
	}

	.title {
		width: 352rpx;
		height: 168rpx;
		font-size: 44rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #ffffff;
		position: absolute;
		top: 120rpx;
		left: 40rpx;
		line-height: 84rpx;
	}

	.lgoin {
		position: absolute;
		top: 382rpx;
		width: 670rpx;
		height: 720rpx;
		background: #ffffff;
		box-shadow: 0px 0px 12rpx 0px rgba(189, 189, 189, 0.5);
		border-radius: 40rpx;
		margin: 0 auto;
		left: 40rpx;
		display: flex;
		flex-direction: column;
		align-items: center;

		input {
			width: 570rpx;
			height: 100rpx;
			background: #f1f3f6;
			border-radius: 16rpx;
			padding-left: 30rpx;
			padding-right: 30rpx;
			margin-bottom: 40rpx;
		}

		view {
			font-size: 40rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 700;
			color: #000000;
			margin: 60rpx 0rpx;
		}
	}

	.btn {
		width: 630rpx;
		height: 95rpx;
		background: #00809f;
		border-radius: 16rpx;
		color: #fff;
		margin-top: 50rpx;
		font-size: 32rpx;
		line-height: 95rpx;
	}
</style>